/**
 * 集成测试文件解析接口测试用例
 *
 * Created by nongzhizhong on 2021/11/25.
 */
const chai = require('chai');
const should = chai.should(); // eslint-disable-line no-unused-vars
chai.use(require('chai-http'));
const common = require('../../../common');
const Administrator = require('../../../../models/administrator');
const File = require('../../../../models/file');
const benchmark = require('./../../../../benchmark/integration-test/tree');
module.exports = describe('/analyse-files test', function () {
  const administrator = new Administrator();
  let project = {};
  let projectVersion = {};
  const newUserIds = [];
  before(function (done) {
    administrator.login()
      .then(() => administrator.createRandomTester())
      .then((tester) => {
        newUserIds.push(tester.userId);
        return tester.createRandomProject();
      })
      .then((res) => {
        project = res;
        return project.createRandomIntegrationVersion(benchmark.files);
      })
      .then((res) => {
        projectVersion = res;
        done();
      })
      .catch(done);
  });
  after(function (done) {
    administrator.removeUsers(newUserIds)
      .then(() => {
        done();
      })
      .catch(done);
  });
  // 主版本和集成测试版本解析文件树解析状态隔离
  it('it should isolation parse unitTest and integrationTest ', function (done) {
    let unitTestFiles;
    project.getVersion(projectVersion.masterVersionId)
      .then((res) => {
        res.project = projectVersion.project;
        const file = new File(res, res.rootDirectory.fileId);
        return file.getTree();
      })
      .then(async (files) => {
        unitTestFiles = files;
        const file = new File(projectVersion, projectVersion.rootDirectory.fileId);
        await file.analyse();
        return file.getTree();
      }).then((integrationTestFiles) => {
        common.should.be.equal.tree(integrationTestFiles.tree, benchmark.result.parseTree);
        common.should.be.equal.tree(unitTestFiles.tree, benchmark.result.tree);
        done();
      })
      .catch(done);
  });
});
